package leetcode.easy.q141;

import leetcode.util.ListNode;

public class Q {
}

/**
 * 快追上慢，则有环
 */
class Solution {
    public boolean hasCycle(ListNode head) {
        if (head == null || head.next == null) {
            return false;
        }
        ListNode step = head;
        head = head.next;
        while (step != head) {
            if (head == null || head.next == null) {
                return false;
            }
            step = step.next;
            head = head.next.next;
        }
        return true;
    }
}